local skel = fk.CreateSkill{--定义
  name = "kpaI__pinger",
  tags = { Skill.Compulsory },--锁定技标签
}

local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{--翻译
  ["kpaI__pinger"] = "萍珥",
  [":kpaI__pinger"] = "锁定技，至你距离1以内的角色回合开始时，其令你摸两张牌或视为对你使用一张【移花接木】。"..
  "本回合结束时，你将其他角色的“萍珥”牌当等量张【杀】对其使用。",
  ["#kpaI__pinger"] = "萍珥：令 %src 摸两张牌或视为对 %src 使用一张【移花接木】，因此获得的牌明置。",
  ["kpaI__pinger1_ask"] = "令 %src 摸两张牌",
  ["kpaI__pinger2_ask"]= "视为对 %src 使用一张【移花接木】",
  ["kpaI__pinger3_ask"]= "将所有“萍珥”牌当【杀】对 %src 使用",

  ["$kpaI__pinger1"] = "滚滚江水东流去，别有孤萍朝夕浮。",
  ["$kpaI__pinger2"] = "去后故人双别泪，春深逐客一浮萍。",
}

skel:addEffect(fk.AfterCardsMove,{
  can_refresh = function (self, event, target, player, data)
    if player:getMark("kpaI__pinger") > 0 and player:hasSkill(skel.name) then
      for _, move in ipairs(data) do
        if move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.skillName == skel.name or move.skillName == "graft_and_transplant_skill" then--应该不至于说这期间还有其他技能印了张移花接木吧？
        --local cards ={}
        for _, info in ipairs(move.moveInfo) do
          --table.insertIfNeed(cards, info.cardId)
          room:addCardMark(Fk:getCardById(info.cardId),"kpaI__pinger-inhand-turn",1)
        end
        --DIY.showCards(move.to,cards,Player.HistoryTurn)
      end
    end
  end
})

skel:addEffect(fk.TurnStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)and (target == player or target:distanceTo(player) <= 1)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:setMark("kpaI__pinger",1)
    --
    local choices
    local textall = {"kpaI__pinger1_ask:"..player.id,"kpaI__pinger2_ask:"..player.id}
    local text = {"kpaI__pinger1_ask:"..player.id,"kpaI__pinger2_ask:"..player.id}
    if player == target or player:isNude() then
      table.remove(text,2)
    end
    choices = room:askToChoice(target, {
      choices = text,
      skill_name = skel.name,
      prompt = "#kpaI__pinger:".. player.id,
      cancelable = false,
      all_choices = textall,
    })
    if choices:startsWith("kpaI__pinger1_ask") then
      player:drawCards(2,skel.name)
    elseif choices:startsWith("kpaI__pinger2_ask") then
      room:useVirtualCard("graft_and_transplant", nil, target, player, skel.name)
    end
    --
    player:setMark("kpaI__pinger",0)
  end,
})

skel:addEffect(fk.TurnEnd, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    for _,p in ipairs(room:getAllPlayers())do
      for _,c in ipairs(p:getCardIds("h"))do
        local card = Fk:getCardById(c)
        if card:getMark("kpaI__pinger-inhand-turn") > 0 then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _,p in ipairs(room:getOtherPlayers(player)) do
      local cards = {}
      for _,c in ipairs(p:getCardIds("h"))do
        local card = Fk:getCardById(c)
        if card:getMark("kpaI__pinger-inhand-turn") > 0 then
          table.insert(cards,c)
        end
      end
      while #cards > 0 do
        local usecard = Fk:cloneCard("slash")
        usecard.skillName = skel.name
        usecard.subcards = {cards[1]}
        table.remove(cards,1)
        room:useCard({
          from = player,
          card = usecard,
          tos = {p}
        })
      end
    end
  end,
})


return skel